package com.project.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ClassBean;
import com.project.bean.RoomBean;
import com.project.bean.StudentBean;
import com.project.mapper.IClassMapper;
import com.project.mapper.IRoomMapper;
import com.project.mapper.IStudentMapper;
import com.project.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService implements IStudentService {
    @Autowired
    public IStudentMapper studentMapper;
    @Autowired
    public IClassMapper classMapper;
    @Autowired
    public IRoomMapper roomMapper;
    @Override
    public void checkIn(StudentBean studentBean) {
        studentMapper.insert(studentBean);
    }

    @Override
    public void checkOut(Integer studentId) {
       studentMapper.deleteById(studentId);
    }

    @Override
    public void changeRoom(Integer studentId, Integer newRoomId) {
        StudentBean stu = studentMapper.selectById(studentId);
        stu.setRoomId(newRoomId);
        studentMapper.updateById(stu);
    }

    @Override
    public StudentBean findById(Integer studentId) {
        return studentMapper.findById(studentId);
    }

    @Override
    public IPage<StudentBean> findStudents(String name, String className, String roomName, Integer pageNum) {

        return studentMapper.findStudents(new Page<>(pageNum,2),name,className,roomName);
    }
}
